package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.converter.StringToEnumConverterFactory;
import com.atguigu.lease.web.admin.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.interceptors.AuthenticationAdminInterceptor;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
//    todo 单独为一个枚举类写 其他的枚举类没法用 所以需要使用转换工厂

    @Autowired
    private StringToEnumConverterFactory stringToEnumConverterFactory;
    @Autowired
    private AuthenticationAdminInterceptor authenticationAdminInterceptor;

    @Value("${admin.auth.path-pattern.exclude}")
    private String excludePathPatterns;
    @Value("${admin.auth.path-pattern.include}")
    private String includePathPatterns;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationAdminInterceptor)
                .addPathPatterns(includePathPatterns).excludePathPatterns(excludePathPatterns);
    }
}
